﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using YGWebMobileApi.Data;
using OneMile.DAL;
using OneMile.Common;
using OneMile.Entity.Model;
using System.Text;

namespace YGWebMobileApi.APIs
{
     [MobileAPI(Code = "MC0102", Name = "用户获取商家详情")]
    public class UGetShopDetailsById: BaseAPI, IProcessMessage
    {
        private DALUShops dalShop;
        protected DALUShops DalShop
        {
            get
            {
                if (dalShop == null)
                {
                    dalShop = DALFactory.getInstance().CreateUShopsDAL();
                }
                return dalShop;
            }
        }
        #region IProcessMessage 成员

        public MobileRspMsg ProcessMessage(MobileReqMsg reqMsg)
        {
            try
            {
                MobileRspMsg rspMsg = new MobileRspMsg(reqMsg);

                string ShopId = reqMsg.Body.GetFieldValue("ShopsId");

                if (String.IsNullOrEmpty(ShopId))
                {
                    rspMsg.Head.RspCode = MessageCode.Paramter_Empty.Code;
                    rspMsg.Head.RspMsg = MessageCode.Paramter_Empty.Msg;
                    return rspMsg;
                }

                EShopsInfo shop = (EShopsInfo)DalShop.GetShopDetailsByID(ShopId);

                rspMsg.Body.AddField("ShopsId", shop.ShopsId.TString());
                rspMsg.Body.AddField("ShopsName", shop.ShopsName);
                rspMsg.Body.AddField("ShopsAddress", shop.ShopsAddress);
                rspMsg.Body.AddField("ShopsTel", shop.ShopsTel);
                rspMsg.Body.AddField("ShopsPraise", shop.ShopsPraise.TString());
                rspMsg.Body.AddField("ShopsPoor", shop.ShopsPoor.TString());
                rspMsg.Body.AddField("ShopsType", shop.ShopsType);
                rspMsg.Body.AddField("RecommendedDishes", shop.RecommendedDishes);
                rspMsg.Body.AddField("OpeningHours", shop.OpeningHours);
                rspMsg.Body.AddField("Consumption", shop.Consumption.TString("F1"));
                rspMsg.Body.AddField("LowestPrice", shop.LowestPrice.TString("F1"));
                rspMsg.Body.AddField("Freight", shop.Freight.TString("F1"));
                rspMsg.Body.AddField("LastLoginTime", shop.LastLoginTime);
                rspMsg.Body.AddField("PromotionsId", shop.PromotionsId.TString());
                rspMsg.Body.AddField("PromotionsTitle", shop.PromotionsTitle.TString());
                rspMsg.Body.AddField("DeliveryDistance", shop.DeliveryDistance.TString("F1"));
                rspMsg.Head.RspCode = MessageCode.Success.Code;
                rspMsg.Head.RspMsg = MessageCode.Success.Msg;

                return rspMsg;
            }
            catch (Exception e)
            {
                ErrorLogWriter.Write("UGetShopDetailsById-" + e);
                throw e;
            }
        }

        #endregion
    }
}